/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.jm.financeiro.datamodel;

import br.jm.financeiro.entity.Assunto;
import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author joao
 */
public class LazySelectedAssunto extends ListDataModel<Assunto> implements SelectableDataModel<Assunto>, Serializable { 

    public LazySelectedAssunto() {
        
    }
    
    public LazySelectedAssunto(List<Assunto> data) {
        super(data);
    }
    
    @Override
    public Assunto getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Assunto> assuntos = (List<Assunto>) getWrappedData();
        
        for(Assunto assunto : assuntos) {
            if(assunto.getIdAssunto().toString().equals(rowKey))
                return assunto;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(Assunto assunto) {
        return assunto.getDscAssunto();
    }
}

